<template lang="jade">
div
  h-loader-full(url='loader',:setdata='false')
  h-data-updater
  m-title(icon='add',name='添加培训课程')
  table.single
    mf-row(name='所属培训学校') {{p.sname + '(' + show[p.school_show] + ')'}}
    mf-row(name='培训课程显示位置')
      select(v-model='p.show',placeholder='请选择显示位置',v-if='p.school_show == 0')
        option(value='', selected) 请选择
        option(v-for='(n,i) in show', :value='i') {{n}}
      span(v-if='p.school_show != 0') {{show[p.show]}}
    mf-row(name='课程名称')
      input(type = 'text',v-model='p.name',placeholder='请填写课程名称')


    mf-row(name='是否免费')
      select(v-model='p.free',placeholder='是否免费')
        option(v-for='(s,i) in free_arr', :value='s.id') {{s.name}}
    


    mf-row(name='视频地址')
      input(type = 'text',v-model='p.vd_src',placeholder='请填写视频地址')
    mf-row(name='视频时长')
      input(type = 'text',v-model='p.vtime',placeholder='请填写视频时长')

    //- mf-row(name='创建时间：'): input(type='datetime-local',v-model='p.c_time')
    mf-row(name='观看人数')
      input(type = 'text',v-model='p.watch_num_input',placeholder='请填写观看人数') 
    mf-row(name='费用价格')
      input(type = 'text',v-model='p.money',placeholder='请填写费用价格') 
    mf-row(name='课程地点')
      input(type = 'text',v-model='p.address',placeholder='请填写课程地点') 
    mf-row(name='课程选择 | 间隔')
      input(type = 'text',v-model='p.select',placeholder='') 




    mf-row(name='图标图片')
      mf-upload(uploadid='img', amount='1',project='xiongan', category='logo',:data='p.icon',@upload_data='text',style='marginTop:20px')
      p(style='marginBottom:0px') 图标图片尺寸 80px（宽）*60px（高）
    mf-row(name='课程内容（公共描述）')
      textarea#con.editor(style='width: 500px; height: 200px;', v-model='p.content') {{p.content}}
    div(style = 'display:none')
      mf-row(name='培养目标（公共描述）')
        textarea#target.editor(style='width: 500px; height: 200px;', v-model='p.target') {{p.target}}
      mf-row(name='学制（公共描述）')
        textarea#system.editor(style='width: 500px; height: 200px;', v-model='p.system') {{p.system}}
      mf-row(name='就业方向')
        textarea#direction.editor(style='width: 500px; height: 200px;', v-model='p.direction') {{p.direction}}
      mf-row(name='是否在首页显示')
        select(v-model='p.ishome',placeholder='请选择')
          option(value='', selected) 请选择
          option(v-for='(n,i) in ishome', :value='i') {{n}}

    mf-row(name='是否启用')
      select(v-model='p.active',placeholder='请选择')
        option(value=1) 启用
        option(value=0) 禁用
    mf-row
      button(@click='button') 确认提交
</template>

<script>
export default {
	data () {
		return {
      loader:{
        p:'cultivate/cultivate/list?id=' + this.$query.get('culid'),
      },
      show:['两端显示','用户端','企业端'],
      p:{},
      ishome:['否','是'],
      free_arr:[
        {
          id:0,
          name:"免费"
        },
        {
          id:1,
          name:"收费"
        }
      ],


		}
	},
	methods: {
    loadAfter(res){
      this.p = res.p[0][0]
      this.p.icon = this.p.icon.split('|')
      // this.p.c_time = new Date(this.p.c_time * 1000).format("yyyy-MM-ddThh:mm")
      con.sync()
      target.sync()
      system.sync()
      direction.sync()
      con.html(this.p.content);
      target.html(this.p.target);
      direction.html(this.p.direction);
      system.html(this.p.system);
		},
    text(data){
			this.p.icon = data
		},
    button(){
      // con.sync()
      // target.sync()
      // system.sync()
      // direction.sync()
      this.p.content = this.$dom.id('con').value
      this.p.target = this.$dom.id('target').value
      this.p.system = this.$dom.id('system').value
      this.p.direction = this.$dom.id('direction').value

      this.data = {
        sid:'',
        show:'',
        name:'',
        free:'',
        vd_src:'',
        vtime:'',
        // c_time:'',
        watch_num_input:'',
        money:'',
        address:'',
        select:'',
        icon:[],
        content:'',
        target:'',
        system:'',
        direction:'',
        ishome:'',
        number:'',

      };
      for(var key in this.p){
        if(key in this.data){
          this.data[key] = this.p[key];
        }
      }

      console.log(this.data);
      var init_num = 0;
      for(var key in this.data){
        if(this.data[key].toString() == ""){
          var must_str = "请填写";
          if(key == "sid" || key == "show"){
            must_str = "请选择";
          };
          if(key == "free" ||key == "vd_src" || key=="watch_num_input" || key=="address" || key=="content" || key=="target" || key=="system" || key=="direction" || key=="ishome" || key=="number" || key=="money"|| key=="sid" ||  key=="select" || key=="select"){
            init_num++;
            continue;
          };
          this.$msg.error(must_str+$(".single").find("th").eq(init_num).text());
          return false;
        };
        init_num++;
      }


      // if(this.p.show !=0 && this.p.show !=1 && this.p.show !=2){
      //   this.$msg.error('请选择显示位置!')
      //   return
      // }
      // if(this.p.name == ''){
      //   this.$msg.error('请填写课程名称!')
      //   return
      // }
      // if(this.p.icon.length == 0 ){
      //   this.$msg.error('请上传图片!')
      //   return
      // }
      // if(this.p.sid == ''){
      //   this.$msg.error('请选择所属学校!')
      //   return
      // }
      // if(this.p.mobile == ''){
      //   this.$msg.error('请填写联系方式!')
      //   return
      // }
      // if( this.p.content == ''){
      //   this.$msg.error('请填写课程内容!')
      //   return
      // }
      // if(this.p.target == ''){
      //   this.$msg.error('请填写培养目标!')
      //   return
      // }
      // if( this.p.system == ''){
      //   this.$msg.error('请填写学制!')
      //   return
      // }
      // if(this.p.direction == ''){
      //   this.$msg.error('请填写就业方向!')
      //   return
      // }
      // if(this.p.ishome != 0 && this.p.ishome != 1){
      //   this.$msg.error('请选择是否在首页显示!')
      //   return
      // }
      // 
      // 
      // 
      this.$ajax.put('cultivate/edit/cultivate',this.p,(res)=>{
        this.$msg.success(res.message)
        setTimeout("window.location.reload()",1000)
      },(res)=>{
        this.$msg.error(res.message)
      })
    }
	}
}
</script>
